<?php

/**
 * This is the model class for table "tbl_book".
 *
 * The followings are the available columns in table 'tbl_book':
 * @property integer $bookID
 * @property string $bookName
 * @property string $language
 * @property string $author
 * @property string $translater
 * @property string $pub
 * @property string $banci
 * @property string $price
 * @property string $ISBN
 * @property integer $pageCount
 * @property string $typeCode
 * @property string $fcode
 * @property string $cover
 * @property string $intro
 *
 * The followings are the available model relations:
 * @property Bbrecords[] $bbrecords
 * @property Bookstate $bookstate
 */
class Book extends CActiveRecord
{
	
	/**
	 * 定义图书编目相关的字符常量
	 */
	const MENU_NAME = '图书编目';
	const MENU_CREAT = '新建书目';
	const MENU_UPDATE = '更新书目';
	const MENU_DEL = '删除书目';
	const MENU_ADMIN = '管理书目';
	const MENU_COPY = '套录书目';
	const MENU_BROWSE = '浏览书目';
	
	const LANG_CN='中文';
	const LANG_EN='英文';
	const LANG_NAXI='纳西象形文';
	
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Book the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_book';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('pageCount', 'numerical', 'integerOnly'=>true),
			array('bookName', 'length', 'max'=>51),
			array('language', 'length', 'max'=>6),
			array('author, translater', 'length', 'max'=>21),
			array('pub', 'length', 'max'=>31),
			array('banci', 'length', 'max'=>9),
			array('price', 'length', 'max'=>8),
			array('ISBN', 'length', 'max'=>13),
			array('typeCode', 'length', 'max'=>20),
			array('fcode', 'length', 'max'=>4),
			array('cover', 'length', 'max'=>200),
			array('intro', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('bookID, bookName, language, author, translater, pub, banci, price, ISBN, pageCount, typeCode, fcode, cover, intro', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'bbrecords' => array(self::HAS_MANY, 'Bbrecords', 'bookID'),
			'bookstate' => array(self::HAS_ONE, 'Bookstate', 'bookID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'bookID' => '图书编号',
			'bookName' => '图书名称',
			'language' => '语言',
			'author' => '作者',
			'translater' => '译者',
			'pub' => '出版社',
			'banci' => '版次',
			'price' => '价格',
			'ISBN' => 'ISBN',
			'pageCount' => '页数',
			'typeCode' => '分类号',
			'fcode' => '四角码',
				'cover'=>'封面',
				'intro'=>'简介',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('bookID',$this->bookID);
		$criteria->compare('bookName',$this->bookName,true);
		$criteria->compare('language',$this->language,true);
		$criteria->compare('author',$this->author,true);
		$criteria->compare('translater',$this->translater,true);
		$criteria->compare('pub',$this->pub,true);
		$criteria->compare('banci',$this->banci,true);
		$criteria->compare('price',$this->price,true);
		$criteria->compare('ISBN',$this->ISBN,true);
		$criteria->compare('pageCount',$this->pageCount);
		$criteria->compare('typeCode',$this->typeCode,true);
		$criteria->compare('fcode',$this->fcode,true);
// 		$criteria->compare('cover',$this->cover,true);
// 		$criteria->compare('intro',$this->intro,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}